/**
 * Created by jimshi0912 on 15/11/2.
 */
(function () {
    angular.module('my-tabs.directives')
        .directive('promotionThumb', promotionThumb);

    function promotionThumb() {
        return {
            restrict: 'E',
            scope: {
                promotion: '='
            },
            templateUrl: 'views/explore/promotion-thumb.html',
            controller: ['$scope', '$state', 'md5', '$sce', 'appService',
                function ($scope, $state, md5, $sce, appService) {
                    $scope.openPromotion = function () {
                        var frameId = md5.createHash($scope.promotion.link || '');
                        appService.putFrame({
                            id: frameId,
                            name: $scope.promotion.title,
                            link: $sce.trustAsResourceUrl($scope.promotion.link)
                        })
                        $state.go('main.frame', {frameId: frameId});
                    };
                }],
            link: function (scope, element, attrs) {

            }
        }
    }
})();
